package com.jincp.common.networkstate;


import android.os.Handler;
import android.os.Looper;

import java.util.Observable;

/**
 * 网络通知事件，上层界面可以订阅此事件
 */
public class NetWorkEvent extends Observable {


    private volatile static NetWorkEvent instance;

    private NetWorkEvent(){
    }

    public static NetWorkEvent getInstance(){
        if (instance == null) {
            synchronized (NetWorkEvent.class) {
                if (instance == null) {
                    instance = new NetWorkEvent();
                }
            }
        }
        return instance;
    }

    public void onNetworkState(boolean isNetworkAvailable, NetInfo netInfo) {
        setChanged();
        notifyObservers(netInfo);
    }


    /**
     * 清理消息监听
     */
    public void clear(){
        deleteObservers();
        instance = null;
    }
}
